<template>
	<view class="h-full overflow-hidden">
		<image src="/static/common/bg.png" mode="widthFix" style="" class="absolute w-full"></image>

		<div class="relative z-10 h-full flex flex-col">
			<div>
				<div class="center pb-25" style="padding-top: 110rpx;">消息</div>
				<div class="tab between" style="justify-content: space-around;">
					<div class="item font-bold fz32 text-black" @click="tabIndex = 0"
						:class="{ active: tabIndex == 0 }">为我提供线索
						<div class="line"></div>
					</div>
					<div class="item font-bold fz32 text-black" @click="tabIndex = 1"
						:class="{ active: tabIndex == 1 }">资源库
						<div class="line"></div>
					</div>
				</div>
			</div>
			<div class="list bg-white h-full" style="overflow: auto;" v-if="tabIndex == 0">
				<!-- 线索列表 资料库列表  共用一个列表UI -->
				<div class="item flex-col mb-16 py-28 px-24 rounded-22 mb-20" v-for="item in list"
					style="background-color: #F8F8F8;">
					<div class="flex w-full">
						<div class="icon w-90 h-90 avatar flex-shirnk-0">
							<image :src="item.me_img" mode="aspectFill" class="w-full h-full rounded-50"></image>
						</div>
						<div class="ml-20 w-full">
							<div class="between w-full">
								<div class="flex">
									<div class="text-white font-bold"
										:style="{ background: 'url(' + item.ph_bj_url + ')' }"
										style="padding: 10rpx 15rpx; font-size: 24rpx;background-size: 100% 100%;border-radius: 10rpx;">
										{{ item.label_name }}
									</div>

									<div class="fz24 text-gray-16 ml-8">
										{{ item.me_nick_name }}
									</div>
								</div>
								<div class="fz20 text-gray-a4">{{ item.add_time }} 
								 <text v-if="item.is_read==0" style="color: red;font-weight: bold; margin-left: 5px; margin-right: 5px;">未读</text>
								 <text v-if="item.is_read==1" style="color: #AC5FF8;font-weight: bold; margin-left: 5px; margin-right: 5px;">已读</text></div>
							</div>
							<div class="fz20 text-gray-a4 mt-20">{{ item.word }}</div>
						</div>
					</div>
					<div class="line mt-20"></div>
					
					<div style="display: flex;">
						<div class="mt-25 center text-purple fz24" style="width: 45%;margin-left: 5%;" v-if="tabIndex == 0">
							{{item.status_word}}
						</div>
						<div class="mt-25 center text-purple fz24" style="width: 45%;margin-right: 5%;" v-if="tabIndex == 0"
							@click="go2('/pages/detail/detail?forMe=1&id=' + item.id,item.is_chick)">
							查看线索
							<image src="/static/message/right.png" mode="widthFix" class="w-15 ml-8"></image>
						</div>
					</div>
					
				</div>
				<nomore v-if="list.length == 0"></nomore>

			</div>
			<div class="list bg-white h-full" style="overflow: auto;" v-if="tabIndex == 1">
				<!-- 线索列表 资料库列表  共用一个列表UI -->
				<div class="item flex-col mb-16 py-28 px-24 rounded-22 mb-20" v-for="item in Resource"
					style="background-color: #F8F8F8;">
					<div class="flex w-full">
						<div class="w-full">
							
							<div class="between w-full">
								<div class="icon w-90 h-90 avatar flex-shirnk-0">
									<image :src="item.me_img" mode="aspectFill" class="w-full h-full rounded-50"></image>
								</div>
								<div class="flex">
									<div style="padding: 5px 2px; font-size: 24rpx;">{{ item.label_name }}</div>
									<div class="fz24 text-gray-16">
										{{ item.resource_name||item.me_nick_name }}
									</div>
								</div>
								<div class="fz20 text-gray-a4">{{ item.add_time }}</div>
							</div>
							<div class="fz20 text-gray-a4 mt-20">{{ item.word }}</div>
							
						</div>
					</div>
					<div class="line mt-20"></div>
					<div class="mt-25 center text-purple fz24" v-if="tabIndex == 1"
						@click="go2('/pages/detail/detail?forOther=1&item=' + JSON.stringify(item),item.is_chick)">
						查看匹配
						<image src="/static/message/right.png" mode="widthFix" class="w-15 ml-8"></image>
					</div>
				</div>
				<nomore v-if="Resource.length == 0"></nomore>

			</div>

		</div>
		<div class="mask flex"  style="justify-content: center;align-items: flex-start;padding-top: 320rpx;" v-if="modalShow"> <!--@click="readedFn2"-->
			<div class="flex-col relative" style="margin-top:100rpx">
				<image src="/static/mask/line.png" class="absolute" mode="widthFix"
					style="width:170rpx;right:-50rpx; top:-250rpx"></image>
				<image src="/static/mask/title.png" mode="widthFix" style="width:500rpx"></image>
				<image src="/static/mask/pic.png" mode="widthFix" style="width:500rpx"></image>
				<div class="center mt-50" style="display: none;">
					<image src="/static/mask/confirm.png" mode="widthFix" style="width:214rpx"></image>
				</div>
			</div>
		</div>
	</view>
</template>

<script>
export default {
	data() {
		return {
			tabIndex: 0,
			list: [],
			Resource: [],
			myInfo: {},
			readed: false,
			modalShow: false,
		}
	},
	onShareAppMessage() {
		this.readedFn2()
		return {
			title: '发布消息找到那个他/她',
			path: '/pages/index/index?id='+this.myInfo.me_invite_code,
			imageUrl: "https://seekerxcxoss.yiyankeji.vip/Label/Share_img.png"
		}
	},
	onLoad() {
		this.lists()
		//this.getMyResource()
		this.getMyMessageList2()
		this.getMyInfo();
		
		if(uni.getStorageSync('getIsFx')){
			if(uni.getStorageSync('getIsFx').is_tgxs=='1'){
				this.readed = false
				
				let timestamp = Date.now();
				if(uni.getStorageSync("readed_time3")){
					var readed_time3 = Number(uni.getStorageSync("readed_time3"))
				}else{
					var readed_time3 = 0
				}
				var cha = timestamp-readed_time3;
				if(cha>86400000){
					this.readed = false
				}else{
					if(uni.getStorageSync("readed_time3")){
						this.readed = true
					}
				}
			}else{
				this.readed = true
			}
		}else{
			this.readed = false
			
			let timestamp = Date.now();
			if(uni.getStorageSync("readed_time3")){
				var readed_time3 = Number(uni.getStorageSync("readed_time3"))
			}else{
				var readed_time3 = 0
			}
			var cha = timestamp-readed_time3;
			if(cha>86400000){
				this.readed = false
			}else{
				if(uni.getStorageSync("readed_time3")){
					this.readed = true
				}
			}
		}
		
		console.log(this.readed)
		
	},
	onShow() {
		this.lists()
		this.lists_count()
		this.getMyMessageList2()
		this.getMyInfo();
	},
	methods: {
		readedFn2() {
			this.modalShow = false
			this.readed = true
			
			let timestamp = Date.now();
			uni.setStorageSync("readed_time", timestamp)
		},
		go2(url,i){
			if(i==2){
				uni.showModal({
					content: '抱歉，该寻人已经结束',
				})
			}else{
				if(this.readed==false){
					this.modalShow = true
				}else{
					uni.navigateTo({
						url:url
					})
				}
			}
		},
		getMyInfo() {
		
			var that = this
			uni.request({
				url: getApp().globalData.host + '/api/My/getMyInfo',
				header: {
					memberid: uni.getStorageSync('member_id'),
					membertoken: uni.getStorageSync('member_token'),
				},
				success: (r) => {
					that.myInfo = r.data.data
					console.log("myInfo", that.myInfo)
				},
			})
		},
		lists() {
			var that = this
			uni.request({
				url: getApp().globalData.host + '/api/Seek/getMyMessageList',
				data: {
					message_type: 1
				},
				header: {
					memberid: uni.getStorageSync('member_id'),
					membertoken: uni.getStorageSync('member_token'),
				},
				success: (r) => {
					that.list = r.data.data.list
				},
			})

		},
		lists_count() {
			var that = this
			uni.request({
				url: getApp().globalData.host + '/api/My/getmessagewd',
				data: {
					message_type: 1
				},
				header: {
					memberid: uni.getStorageSync('member_id'),
					membertoken: uni.getStorageSync('member_token'),
				},
				success: (r) => {
					if(r.data.data){
						var count = r.data.data.wd_num
						console.log(count)
						uni.setTabBarBadge({
							index: 3,
							text: String(count)
						})
					}
				},
			})
		
		},
		getMyMessageList2() {
			var that = this
			uni.request({
				url: getApp().globalData.host + '/api/Seek/getMyMessageList',
				data: {
					message_type: 2
				},
				header: {
					memberid: uni.getStorageSync('member_id'),
					membertoken: uni.getStorageSync('member_token'),
				},
				success: (r) => {
					that.Resource = r.data.data.list
				},
			})
		},


		getMyResource() {
			var that = this
			uni.request({
				url: getApp().globalData.host + '/api/Resource/getMyResource',
				data: {
					page: 1, nums: 100
				},
				header: {
					memberid: uni.getStorageSync('member_id'),
					membertoken: uni.getStorageSync('member_token'),
				},
				success: (r) => {
					that.Resource = r.data.data.list
				},
			})

		}
	}
}
</script>

<style lang="less">
page {
	height: 100%;
}

.list {
	border-radius: 29rpx 29rpx 0 0;
	padding: 39rpx 30rpx;
}
.mask {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 99;
	}
.tab {
	.item {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}

	.line {
		width: 84rpx;
		height: 8rpx;
		background-color: #AC5FF8;
		margin-top: 10rpx;
		opacity: 0;
	}

	.active {
		.line {
			opacity: 1;
		}
	}
}
</style>